﻿$(document).ready(function () {
  var s = document.location
  $("#starlist a").each(function () {
    if (this.href == s.toString().split("#")[0]) {
      $(this).addClass("on")
      return false
    }
  })
  $("#starlist li").each(function () {
    $("#starlist li").removeClass("navbar-item")
    if ($("#starlist li ul")) {
      $("#starlist li ul").parent().addClass("menu")
      $("#starlist li ul").addClass("sub")
    }
  })
      //nav
    $("#mnavh").click(function () {
        $("#starlist").toggle();
        $("#mnavh").toggleClass("open");
        $(".sub").hide();
    });
    //nav menu
    $(".menu").click(function (event) {
        $(this).children('.sub').slideToggle();
        $(this).siblings('.menu').children('.sub').slideUp('');
        event.stopPropagation()
    });
    $(".menu a").click(function (event) {
        event.stopPropagation();
    });
    $(".sub li").click(function (event) {
        event.stopPropagation();
    });

  // banner 
  let vsCarousel = new VsCarousel('vsCarousel', {
    effect: 'fade',
    pege: 'center'
  });

  // 导航效果
  document.querySelectorAll('a').forEach(elem => {
    elem.onmouseenter =
      elem.onmouseleave = e => {
        const tolerance = 5;
        const left = 0;
        const right = elem.clientWidth;
        let x = e.pageX - elem.offsetLeft;
        if (x - tolerance < left) x = left;
        if (x + tolerance > right) x = right;
        elem.style.setProperty('--x', `${x}px`);
      };
  });

  //scroll to top
  var offset = 300,
    offset_opacity = 1200,
    scroll_top_duration = 700,
    $back_to_top = $('.icon-top');
  $(window).scroll(function () {
    ($(this).scrollTop() > offset) ? $back_to_top.addClass('cd-is-visible') : $back_to_top.removeClass('cd-is-visible cd-fade-out');
    if ($(this).scrollTop() > offset_opacity) {
      $back_to_top.addClass('cd-fade-out');
    }
  });
  $back_to_top.on('click', function (event) {
    event.preventDefault();
    $('body,html').animate({
      scrollTop: 0,
    }, scroll_top_duration
    );
  });

  // 搜索
  $('#divCalendar dt').html('日历')
  $('#divCalendar dt').css('display','block')
  
  // 标签颜色
  var tagsColor = ['#CCFF99','#99CCFF','#99CCCC','#CCFFCC','#66CCCC','#CCCCFF','#6699CC','#CCFF66','#FF99CC','#6699FF','#00CCFF','#00FF33','#3333CC','#669933','#990033','#999966','#CC0099',
'#CC9999','#CCFF00','#FF9933','#000033','#990066']
  //divTags Math.round(Math.random()*10)
  var liLen = $('#divTags .function_c div ul').children();
  var tagsLen = $('.single .tags p').eq(1).children();
  for (let i = 0; i < liLen.length; i++) {
    liLen.eq(i).children().first().css('color',tagsColor[Math.round(Math.random()*22)]) 
    tagsLen.eq(i).css('color',tagsColor[Math.round(Math.random()*22)]) 
    tagsLen.eq(i).css('borderColor',tagsColor[Math.round(Math.random()*22)]) 
  }
})

zbp.plugin.unbind("comment.reply.start", "system")
zbp.plugin.on("comment.reply.start", "acmeContract", function (id) {
  var i = id
  $("#inpRevID").val(i)
  var frm = $('#divCommentPost')
  var cancel = $("#cancel-reply")

  if (!frm.hasClass("reply-frm"))
    frm.before($("<div id='temp-frm' style='display:none'>")).addClass("reply-frm")
  $('#AjaxComment' + i).before(frm)

  cancel.show().click(function () {
    var temp = $('#temp-frm')
    $("#inpRevID").val(0)
    if (!temp.length || !frm.length) return
    temp.before(frm)
    temp.remove()
    $(this).hide()
    frm.removeClass("reply-frm")
    return false
  })
  try {
    $('#txaArticle').focus()
  } catch (e) {

  }
  return false
})

zbp.plugin.on("comment.get", "acmeContract", function (logid, page) {
  $('span.commentspage').html("Waiting...")
})

zbp.plugin.on("comment.got", "acmeContract", function () {
  $("#cancel-reply").click()
})

zbp.plugin.on("comment.post.success", "acmeContract", function () {
  $("#cancel-reply").click()
})